<template>
  <div v-loading="loading">
    <el-form ref="form" :model="form" :rules="rules" label-width="120px" class="dataForm">
      <el-row>
        <el-col :span="12">
          <el-form-item :label="$t('名称')" prop="title">
            <el-input v-model="form.title" :placeholder="$t('名称')" show-word-limit maxlength="100" />
          </el-form-item>
        </el-col>
        <el-col :span="12">
          <el-form-item :label="$t('专利名称')" prop="patentName">
            <el-input v-model="form.patentName" :placeholder="$t('专利名称')" show-word-limit maxlength="100" />
          </el-form-item>
        </el-col>
        <el-col :span="12">
          <el-form-item :label="$t('申请号/专利号')" prop="patentNum">
            <el-input v-model="form.patentNum" :placeholder="$t('申请号/专利号')" show-word-limit maxlength="50" />
          </el-form-item>
        </el-col>
        <el-col :span="12">
          <el-form-item :label="$t('专利类型')" prop="patentType">
            <el-input v-model="form.patentType" :placeholder="$t('专利类型')" show-word-limit maxlength="50" />
          </el-form-item>
        </el-col>
        <el-col :span="12">
          <el-form-item :label="$t('发明人')" prop="inventor">
            <el-input v-model="form.inventor" :placeholder="$t('发明人')" show-word-limit maxlength="100" />
          </el-form-item>
        </el-col>
        <el-col :span="12">
          <el-form-item :label="$t('法律状态')" prop="lawStatus">
            <el-input v-model="form.lawStatus" :placeholder="$t('法律状态')" show-word-limit maxlength="50" />
          </el-form-item>
        </el-col>
        <el-col :span="12">
          <el-form-item :label="$t('申请人')" prop="applicantName">
            <el-input v-model="form.applicantName" :placeholder="$t('申请人')" show-word-limit maxlength="50" />
          </el-form-item>
        </el-col>
        <el-col :span="12">
          <el-form-item :label="$t('申请日')" prop="applicationTime">
            <el-date-picker
              v-model="form.applicationTime"
              clearable
              style="width: 200px"
              type="date"
              value-format="yyyy-MM-dd"
              :placeholder="$t('申请日')"
            />
          </el-form-item>
        </el-col>
        <el-col :span="12">
          <el-form-item :label="$t('申请公布号')" prop="applicationPublishNum">
            <el-input v-model="form.applicationPublishNum" :placeholder="$t('申请公布号')" show-word-limit maxlength="50" />
          </el-form-item>
        </el-col>
        <el-col :span="12">
          <el-form-item :label="$t('申请公布日')" prop="applicationPublishTime">
            <el-date-picker
              v-model="form.applicationPublishTime"
              clearable
              style="width: 200px"
              type="date"
              value-format="yyyy-MM-dd"
              :placeholder="$t('申请公布日')"
            />
          </el-form-item>
        </el-col>
        <el-col :span="12">
          <el-form-item :label="$t('申请公布号')" prop="appnumber">
            <el-input v-model="form.appnumber" :placeholder="$t('申请公布号')" show-word-limit maxlength="50" />
          </el-form-item>
        </el-col>
        <el-col :span="12">
          <el-form-item :label="$t('代理机构')" prop="agency">
            <el-input v-model="form.agency" :placeholder="$t('代理机构')" show-word-limit maxlength="100" />
          </el-form-item>
        </el-col>
        <el-col :span="12">
          <el-form-item :label="$t('代理人')" prop="agent">
            <el-input v-model="form.agent" :placeholder="$t('代理人')" show-word-limit maxlength="100" />
          </el-form-item>
        </el-col>
        <el-col :span="12">
          <el-form-item :label="$t('全部分类号')" prop="allCatNum">
            <el-input v-model="form.allCatNum" :placeholder="$t('全部分类号')" show-word-limit maxlength="50" />
          </el-form-item>
        </el-col>
        <el-col :span="12">
          <el-form-item :label="$t('法律状态公告日')" prop="patentsDate">
            <el-date-picker
              v-model="form.patentsDate"
              clearable
              style="width: 200px"
              type="date"
              value-format="yyyy-MM-dd"
              :placeholder="$t('法律状态公告日')"
            />
          </el-form-item>
        </el-col>
        <el-col :span="12">
          <el-form-item :label="$t('最新法律状态')" prop="lprs">
            <el-input v-model="form.lprs" :placeholder="$t('最新法律状态')" show-word-limit maxlength="50" />
          </el-form-item>
        </el-col>
        <el-col :span="12">
          <el-form-item :label="$t('公开公告日')" prop="pubDate">
            <el-date-picker
              v-model="form.pubDate"
              clearable
              style="width: 200px"
              type="date"
              value-format="yyyy-MM-dd"
              :placeholder="$t('公开公告日')"
            />
          </el-form-item>
        </el-col>
        <el-col :span="12">
          <el-form-item :label="$t('申请公布号')" prop="pubnumber">
            <el-input v-model="form.pubnumber" :placeholder="$t('申请公布号')" show-word-limit maxlength="50" />
          </el-form-item>
        </el-col>
        <el-col :span="12">
          <el-form-item :label="$t('图片url')" prop="imgUrl">
            <el-input v-model="form.imgUrl" :placeholder="$t('图片url')" show-word-limit maxlength="100" />
          </el-form-item>
        </el-col>
        <el-col :span="12">
          <el-form-item :label="$t('地址')" prop="address">
            <el-input v-model="form.address" :placeholder="$t('地址')" show-word-limit maxlength="100" />
          </el-form-item>
        </el-col>
        <el-col :span="24">
          <el-form-item :label="$t('摘要')" prop="abstracts">
            <el-input v-model="form.abstracts" type="textarea" :placeholder="$t('摘要')" show-word-limit maxlength="1000" />
          </el-form-item>
        </el-col>
        <el-col :span="24">
          <el-form-item :label="$t('详情')" prop="detail">
            <el-input v-model="form.detail" type="textarea" :placeholder="$t('详情')" show-word-limit maxlength="1000" />
          </el-form-item>
        </el-col>
      </el-row>
    </el-form>
    <div slot="footer" class="dialog-footer" style="text-align: right;">
      <!--保存 取消按钮-->
      <save-btn has-permi="company:patents" />
    </div>
  </div>
</template>

<script>
    import { saveCompanyPatents, getCompanyPatents } from '@/api/company/Patents/companyPatents'
    export default {
        data() {
            return {
                // 表单参数
                form: {},
                // 遮罩层
                loading: false,
                // 表单校验
                rules: {
                applicantName: [
                    { required: true, message: this.$t('必填信息'), trigger: 'blur' }
                ],
                inventor: [
                    { required: true, message: this.$t('必填信息'), trigger: 'blur' }
                ],
                lawStatus: [
                    { required: true, message: this.$t('必填信息'), trigger: 'blur' }
                ],
                patentName: [
                    { required: true, message: this.$t('必填信息'), trigger: 'blur' }
                ],
                patentNum: [
                    { required: true, message: this.$t('必填信息'), trigger: 'blur' }
                ],
                patentType: [
                    { required: true, message: this.$t('必填信息'), trigger: 'blur' }
                ]
                }
            }
        },
        created() {
        },
        methods: {
            // 初始化数据
            init(data) {
                this.loading = true
                if (data != null && data.id !== undefined) {
                    getCompanyPatents(data.id).then(response => {
                        this.form = response.data
                        this.loading = false
                    }).catch(() => {
                      this.loading = false
                    })
                } else {
                    this.reset()
                    this.loading = false
                }
            },
            // 表单重置
            reset() {
                this.form = {
                    id: undefined,
                    companyId: this.$route.query.companyId,
                    abstracts: undefined,
                    address: undefined,
                    agency: undefined,
                    agent: undefined,
                    allCatNum: undefined,
                    applicantName: undefined,
                    applicationPublishNum: undefined,
                    applicationPublishTime: undefined,
                    applicationTime: undefined,
                    appnumber: undefined,
                    imgUrl: undefined,
                    inventor: undefined,
                    lawStatus: undefined,
                    patentsDate: undefined,
                    lprs: undefined,
                    patentName: undefined,
                    patentNum: undefined,
                    patentType: undefined,
                    pubDate: undefined,
                    pubnumber: undefined,
                    title: undefined,
                    detail: undefined,
                    delFlag: undefined,
                    createBy: undefined,
                    createTime: undefined,
                    updateBy: undefined,
                    updateTime: undefined
                }
                this.resetForm('form')
            },
            // 取消按钮
            cancel() {
                this.$parent.$parent.formOpen = false
                this.$parent.$parent.reset()
            },
            // 关闭form页面
            closeForm() {
                // 关闭form页面遮罩层
                this.loading = false
                // 关闭form页面
                if (this.$parent.$parent.formOpen !== undefined) {
                  this.$parent.$parent.formOpen = false
                }
                // 刷新list页面
                if (this.$parent.$parent.getList !== undefined) {
                  this.$parent.$parent.getList()
                }
            },
            /** 提交按钮 */
            submitForm() {
                this.$refs['form'].validate(valid => {
                    if (valid) {
                        this.loading = true
                        saveCompanyPatents(this.form).then(response => {
                            if (response.code === 200) {
                                this.msgSuccess(this.$t('保存成功'))
                              if (this.$route.query.companyId) {
                                this.$store.dispatch('bussRisk/UPDATE_BUSS_RISK_COUNT', { id: this.$route.query.companyId })
                              }
                                this.closeForm()
                            } else {
                                this.msgError(response.msg)
                            }
                            this.loading = false
                        })
                    } else {
                       this.locationError(document)
                    }
                }).catch(() => {
                    this.loading = false
                })
           }
        }
    }
</script>
